package com.ugrow.Study_System.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.ugrow.Study_System.R;

public class MainActivity extends AppCompatActivity {

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
    private static String TAG="MainActivity";
//连续点击两次返回按键,退出应用
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//
//        return super.onKeyDown(keyCode, event);
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e(TAG,"test_error");
        ImageView imageView = (ImageView) findViewById(R.id.kefu_head_call);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                Intent call = new Intent();
//                //跳转到拨号页面,用户自己拨打,不需要权限
//                call.setAction(Intent.ACTION_DIAL);
//                call.setData(Uri.parse("tel:" + "4008823823"));
//                startActivity(call);
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("tel");
                builder.setMessage("确定要拨打电话:400823823吗");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:400823823"));

                        startActivity(intent);
                    }
                });
//                builder.setNegativeButton("不要", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        Toast.makeText(MainActivity.this, "取消拨号请求", Toast.LENGTH_SHORT).show();
//                    }
//              });
                builder.setNegativeButton("不要",null);

                builder.create().show();




            }
        });


        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
//        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public void register(View view) {//跳转到注册页面
        Intent intent = new Intent(MainActivity.this, Register.class);
        startActivity(intent);



    }

    public void login(View view) {//跳转到登录页面
        Intent intent = new Intent(MainActivity.this, Login.class);
        startActivity(intent);

    }


}
